package leetcode_2301_2400;

import node.ListNode;

import java.util.Arrays;

public class LeeCode_2326 {
    public static void main(String[] args) {

    }
    private static int[][] spiralMatrix(int m, int n, ListNode head) {
        int[][] ans = new int[m][n];
        for (int i = 0; i < m; i++) {
            Arrays.fill(ans[i], -1);
        }
        int[][] vis = new int[m][n];
        char dir = 'r';
        int x = 0, y = 0;
        while (head != null) {
            switch (dir) {
                case 'r': {
                    if (y >= n || vis[x][y] == 1){
                        dir = 'd';
                        y--;
                        x++;
                        continue;
                    }
                    ans[x][y] = head.val;
                    vis[x][y] = 1;
                    y++;
                    break;
                }
                case 'l': {
                    if (y < 0 || vis[x][y] == 1){
                        dir = 'u';
                        y++;
                        x--;
                        continue;
                    }
                    ans[x][y] = head.val;
                    vis[x][y] = 1;
                    y--;
                    break;
                }
                case 'd': {
                    if (x >= m || vis[x][y] == 1){
                        dir = 'l';
                        x--;
                        y--;
                        continue;
                    }
                    ans[x][y] = head.val;
                    vis[x][y] = 1;
                    x++;
                    break;
                }
                case 'u': {
                    if (x < 0 || vis[x][y] == 1){
                        dir = 'r';
                        x++;
                        y++;
                        continue;
                    }
                    ans[x][y] = head.val;
                    vis[x][y] = 1;
                    x--;
                    break;
                }
            }
            head = head.next;
        }
        return ans;
    }
}
